package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.MemberDao;
import com.atguigu.pojo.Member;
import com.atguigu.service.MemberService;
import com.atguigu.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;

/**
 * @program: meinian_parent
 * @author: Mr.Zhuo
 * @create: 2022-02-18 19:58
 **/
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.getByTelephone(telephone);
    }

    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    @Override
    public ArrayList<Integer> findMemberCountByMonth(ArrayList<String> months) {
        ArrayList<Integer> counts = new ArrayList<>();

        for (String month : months) {
            String lastDayOfMonth = DateUtils.getLastDayOfMonth(month);

            Integer count = memberDao.findMemberCountBeforeDate(lastDayOfMonth);
            counts.add(count);
        }
        // 获取完整的日期
        return counts;
    }


}
